package com.hw.blog.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncMdSHa {
//	MessageDigest md;
	String strSRCData = "";
	String strENCData = "";

	public EncMdSHa() {
	}

	public String encrypt_md5(String strData) { // 암호화 시킬 데이터
		strSRCData = "";
		strENCData = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5"); // "MD5 형식으로 암호화"
			md.reset();
			byte[] bytData = strData.getBytes();
			md.update(bytData);
			byte[] digest = md.digest(); // 배열로 저장을 한다.
			for (int i = 0; i < digest.length; i++) {
				strENCData = strENCData
						+ Integer.toHexString(digest[i] & 0xFF).toUpperCase();
			}
		} catch (NoSuchAlgorithmException e) {
			System.out.print("암호화 에러" + e.toString());
		}
		return strENCData; // 암호화된 데이터를 리턴...
	}

	public String encrypt_sha1(String strData) { // 암호화 시킬 데이터
		strSRCData = "";
		strENCData = "";

		try {
			MessageDigest md = MessageDigest.getInstance("SHA1"); // "SHA1 형식으로 암호화"
			md.reset();
			byte[] bytData = strData.getBytes();
			md.update(bytData);
			byte[] digest = md.digest(); // 배열로 저장을 한다.
			for (int i = 0; i < digest.length; i++) {
				strENCData = strENCData
						+ Integer.toHexString(digest[i] & 0xFF).toUpperCase();
			}
		} catch (NoSuchAlgorithmException e) {
			System.out.print("암호화 에러" + e.toString());
		}
		return strENCData; // 암호화된 데이터를 리턴...
	}

	public static void main(String[] args) {
		EncMdSHa th_pw = new EncMdSHa();
		String mdResult = "", shaResult = "";
//		mdResult = th_pw.encrypt_md5("admin");
		shaResult = th_pw.encrypt_sha1("admin");
		
		System.out.println("##cha##[" + th_pw.encrypt_sha1("cha") + "]####");
		System.out.println("##k932619  ##[" + th_pw.encrypt_sha1("k932619") + "]####");
		System.out.println("##admin2610##[" + th_pw.encrypt_sha1("admin2610") + "]####");
		System.out.println("##110505   ##[" + th_pw.encrypt_sha1("110505") + "]####");
		System.out.println("##admin    ##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##webzine  ##[" + th_pw.encrypt_sha1("webzine") + "]####");
		System.out.println("##engmng123##[" + th_pw.encrypt_sha1("engmng123") + "]####");
		System.out.println("##visit    ##[" + th_pw.encrypt_sha1("visit") + "]####");
		System.out.println("##12345    ##[" + th_pw.encrypt_sha1("12345") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		System.out.println("##SHA1##[" + th_pw.encrypt_sha1("admin") + "]####");
		

	}
}
